import unittest
import requests
import time


class meetHereAPITest(unittest.TestCase):
    s = None

    @classmethod
    def setUpClass(cls):
        cls.s = requests.Session()
        url = "http://118.121.200.162:8085/loginCheck.do"
        mydata = {
            "userID": "ljt",
            "password": "123"
        }
        res = cls.s.post(url, data=mydata)

    def test_sendmessage(self):
        url = "http://118.121.200.162:8085/sendMessage"
        now = time.strftime("%Y%m%d%H%M%S", time.localtime())
        mycontent = {
            "userID": "ljt",
            "content": "ljt" + now
        }
        res = self.s.post(url, params=mycontent)
        self.assertEqual(res.status_code, 200)

    def test_getMessageList(self):
        url = "http://118.121.200.162:8085/message/getMessageList"
        p = {
            "page": "1"
        }
        res = self.s.get(url, params=p)
        self.assertEqual(res.status_code, 200)
        # print(res.text)

    def test_fandUserList(self,messageID):
        url = "http://118.121.200.162:8085/message/findUserList"
        p = {
            "page": "1"
        }
        res = self.s.get(url, params=p)
        messageID = res.text[12:17]
        self.assertEqual(res.status_code, 200)
        print(res.text)

    def test_delMessage(self):
        url = "http://118.121.200.162:8085/delMessage.do"
        p = {
            "messageID": "32127"
        }
        res = self.s.post(url, params=p)
        self.assertEqual(res.status_code, 200)
        self.assertIn("true", res.text)
        print(res.text)


if __name__ == '__main__':
    unittest.main()
